# -*- coding:utf-8 -*-

__author__ = 'stevezhou'

import gzwechat_sdk

if __name__ == '__main__':
    wx = gzwechat_sdk.WeChatPublic(appid="wxf987d4ce036e4a40", appsecret="055d128642ba5306c750c4b170762c36")
    # res = wx.get_followers()
    # for wxuser in res['data']['openid']:
    #     user = wx.get_user_info(wxuser)
    #     print user
    
    
    #o8csQuIizVD4lVJIYmvXWBNhFCe0  stevezhou
    #o8csQuNDa7eqTWr92-AfdciRuiYo  wangtianyang
    # aa = wx.send_text_message('o8csQuIizVD4lVJIYmvXWBNhFCe0','from program msg')
    # print aa
    
    #模板ID：yj02t25cN6sUl3353JmOOYrah6YF_PeSpvZWkx_GvJY
    # {{first.DATA}}
    # 用户名称：{{keyword1.DATA}}
    # 咨询内容：{{keyword2.DATA}}
    # {{remark.DATA}}
    # template_data = {
    #             "first": {
    #                "value": "XXX你好，你有一条用户咨询！",
    #                "color": "#173177"
    #             },
    #             "keyword1":{
    #                "value": "周兵",
    #                "color": "#173177"
    #             },
    #             "keyword2":{
    #                "value": "测试发送模板消息",
    #                "color": "#173177"
    #             }
    # }
    # bb = wx.send_template_message('o8csQuIizVD4lVJIYmvXWBNhFCe0', 'yj02t25cN6sUl3353JmOOYrah6YF_PeSpvZWkx_GvJY',template_data)
    # print bb
    
    #https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2fdayrecord%26&response_type=code&scope=snsapi_userinfo&state=dayrecord#wechat_redirect
    #http://isleep.er-cloud.com/gzwx/dayrecord
    
    ## comment by wuyun
    # menu_dict = {
    #                 'button':[
    #                     {
    #                         'type': 'view',
    #                         'name': '每日记录',
    #                         'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2fdayrecord&response_type=code&scope=snsapi_base&state=dayrecord#wechat_redirect'
    #                     },
    #                     {
    #                         'type': 'view',
    #                         'name': '咨询医生',
    #                         'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2fdoctors&response_type=code&scope=snsapi_base&state=doctors#wechat_redirect'
    #                     },
    #                     {
    #                         'name': '我的',
    #                         'sub_button': [
    #                             {
    #                                 'type': 'view',
    #                                 'name': '历史数据',
    #                                 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2fhistorydata&response_type=code&scope=snsapi_base&state=historydata#wechat_redirect'
    #                             },
    #                             {
    #                                 'type': 'view',
    #                                 'name': '医生反馈报告',
    #                                 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2freports%2fget&response_type=code&scope=snsapi_base&state=dayrecords#wechat_redirect'
    #                             },
    #                             {
    #                                 'type': 'view',
    #                                 'name': '医生',
    #                                 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2fgzwx%2fdoctors&response_type=code&scope=snsapi_base&state=doctors#wechat_redirect'
    #                             },
    #                             {
    #                                 'type': 'view',
    #                                 'name': '手环',
    #                                 'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2foauth%2fbong%2findex&response_type=code&scope=snsapi_base&state=bracelet#wechat_redirect'
    #                             }
    #                         ]
    #                     }
    #                 ]}
    
    menu_dict = {
                    'button':[
                        {
                            'name': '我要',
                            'sub_button': [
                                {
                                    'type': 'view',
                                    'name': '写睡前日志',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpatient%2frecord&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '睡眠自评',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpsqi%2frecord&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '测评情绪',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpsy%2frecord&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '询问医生',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpatient%2fmessagelist&response_type=code&scope=snsapi_base&state=a#wechat_redirect',
                                }
                            ]
                        },
                        #{
                        #    'type': 'click',
                        #    'name': 'e康养生',
                        #    'key': 'GOOD_HEALTH'
                        #},
                        {
                            'name': '我的',
                            'sub_button': [
                                {
                                    'type': 'view',
                                    'name': '健康日志',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpatient%2fhistories&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '健康报告',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpatient%2freportlist&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '医生',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpatient%2fdoctorlist&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '服药设置',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2fpill%2fsettings&response_type=code&scope=snsapi_base&state=a#wechat_redirect'
                                },
                                {
                                    'type': 'view',
                                    'name': '智能硬件',
                                    'url': 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf987d4ce036e4a40&redirect_uri=http%3a%2f%2fisleep.er-cloud.com%2fgzwx%2findex%3fredirect%3d%2feroad_bracelet%2foauth%2findex&response_type=code&scope=snsapi_base&state=bracelet#wechat_redirect'
                                },                    
                            ]
                        }
                    ]}
    aa = wx.create_menu(menu_dict)
    print aa
    
    
    #bb = wx.get_menu()
    #print bb
    
    
    # aa = wx.get_user_access_token_fromcode('0118cc15ff586a0f71590c64e65b0daE')
    # print aa
    #
    # bb = wx.get_user_info(aa['openid'])
    # print bb
    
    # bb = wx.send_text_message('oOw-Ps3jtbCqJppT2uuz2vbX9wD8','sgdsgdfd')
    # print bb
    
    # filepath = "/home/stevezhou/tmp/eroad.jpg"
    # f = open(filepath, 'rb')
    # aa = wx.upload_media('image', f)
    # print aa
    #{u'media_id': u'RM4CMYdkrPx1XjPGiavqI9yXXpZM1-AGAkf7sewVCugwJpILih-qVqCW7yvjLO1S', u'created_at': 1431751221, u'type': u'image'}
    
    #bb = wx.send_image_message('oOw-Ps3jtbCqJppT2uuz2vbX9wD8', 'RM4CMYdkrPx1XjPGiavqI9yXXpZM1-AGAkf7sewVCugwJpILih-qVqCW7yvjLO1S')
    #print bb
    
    #获取素材列表
    #material_list = wx.get_material('news', 0, 20)
    #print material_list
    
    print 'finished'
